#First slot
kilwa_cape_missions_slot = {
	slot = 1
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Origins"
	}
	potential = {
		has_dlc = "Origins"
		NOT = { map_setup = map_setup_random }
		tag = ZAN
	}
	has_country_shield = yes

	#Annex Sofala
	zan_annex_sofala = {
		icon = mission_arabian_fort
		required_missions = {  }
		position = 1
		provinces_to_highlight = {
			OR = {
				owned_by = SFA
				AND = {
					province_id = 1186
					NOT = { owned_by = ROOT }
				}
			}
		}
		trigger = {
			owns = 1186
			NOT = { exists = SFA }
		}
		effect = {
			zimbabwe_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			butua_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			lower_zambezi_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}

	#Conquer Mutapa
	zan_mutapan_gold = {
		icon = mission_african_gold
		required_missions = { 
			zan_annex_sofala
		}
		position = 2
		provinces_to_highlight = {
			OR = {
				area = zimbabwe_area
				area = butua_area
				area = lower_zambezi_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = zimbabwe_area
					area = butua_area
					area = lower_zambezi_area
				}
				value = 5
			}
		}
		effect = {
			unlock_estate_privilege = {
				estate_privilege = estate_burghers_control_over_the_mint
			}
			create_conquistador = {
				tradition = 50
			}
		}
	}

	#Discover the Cape
	zan_discover_the_cape = {
		icon = mission_sw_against_the_desert
		required_missions = { 
			zan_mutapan_gold
			zan_build_workshops
		}
		position = 3
		provinces_to_highlight = {
			province_id = 1177
			NOT = { has_discovered = ROOT }
		}
		trigger = {
			has_discovered = 1177
		}
		effect = {
			add_country_modifier = {
				name = zan_expansion_into_the_cape
				duration = 10950
			}
			create_colony_mission_reward = {
				province = 1177
			}
		}
	}

	#Colonize the Cape
	zan_colonize_the_cape = {
		icon = colonize_the_cape
		required_missions = { zan_discover_the_cape }
		position = 4
		provinces_to_highlight = {
			region = south_africa_region
			NOT = { owned_by = ROOT }
		}
		trigger = {
			1177 = {
				is_in_capital_area = yes
			}
		}
		effect = {
			1177 = {
				if = {
					limit = { NOT = { province_has_center_of_trade_of_level = 2 } }
					add_center_of_trade_level = 1
				}
				add_building_construction = {
					building = trade_depot
					speed = 0.5
					cost = 0
				}
			}
			custom_tooltip = zan_colonize_the_cape_ct
			hidden_effect = {
				every_province = {
					limit = {
						OR = {
							region = kongo_region
							region = central_africa_region
						}
						OR = {
							province_has_center_of_trade_of_level = 1
							has_province_modifier = kongo_estuary_modifier
						}
					}
					add_permanent_claim = ROOT
				}
			}
		}
	}

	#Colonize certain provinces in Africa to secure trade
	zan_settle_trade_posts = {
		icon = mission_kon_greatest_power_kongo
		required_missions = { zan_colonize_the_cape }
		position = 5
		provinces_to_highlight = {
			OR = {
				region = kongo_region
				region = central_africa_region
			}
			OR = {
				has_province_modifier = kongo_estuary_modifier
				province_has_center_of_trade_of_level = 1
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					region = kongo_region
					region = central_africa_region
				}
				OR = {
					has_province_modifier = kongo_estuary_modifier
					province_has_center_of_trade_of_level = 1
				}
				value = 4
			}
		}
		effect = {
			add_mercantilism = 10
			add_years_of_trade_income = {
				years = 4
				custom_tooltip = zan_settle_trade_posts_ct
			}
		}
	}
}

#Second slot
kilwa_internal_missions_slot = {
	slot = 2
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Origins"
	}
	potential = {
		has_dlc = "Origins"
		NOT = { map_setup = map_setup_random }
		tag = ZAN
	}
	has_country_shield = yes

	#Re-Establish contact with Persia
	zan_establish_contact_with_persia = {
		icon = mission_into_persia_1
		required_missions = {  }
		position = 1
		provinces_to_highlight = {
			province_id = 2218
		}
		trigger = {
			OR = {
				owns = 2218
				custom_trigger_tooltip = {
					tooltip = zan_establish_contact_with_persia_at
					2218 = {
						OR = {
							infantry_in_province = ROOT
							cavalry_in_province = ROOT
							artillery_in_province = ROOT
						}
					}
				}
				custom_trigger_tooltip = {
					tooltip = zan_establish_contact_with_persia_bt
					2218 = {
						owner = {
							OR = {
								is_subject_of = ROOT
								alliance_with = ROOT
							}
						}
					}
				}
			}
			if = {
				limit = { NOT = { owns = 2218 } }
				2218 = {
					owner = {
						NOT = { war_with = ROOT }
					}
				}
			}
		}
		effect = {
			if = {
				limit = {
					NOT = { owns = 2218 }
				}
				country_event = {
					id = flavor_zan.8
				}
			}
			else = {
				2218 = {
					add_base_tax = 3
					add_base_production = 3
					add_base_manpower = 2
				}
			}
		}
	}

	#Build workshops in Ivory provinces
	zan_build_workshops = {
		icon = mission_into_africa
		required_missions = {  }
		position = 2
		provinces_to_highlight = {
			owned_by = ROOT
			trade_goods = ivory
			has_production_building_trigger = no
		}
		trigger = {
			num_of_owned_provinces_with = {
				trade_goods = ivory
				has_production_building_trigger = yes
				value = 5
			}
		}
		effect = {
			add_years_of_owned_provinces_production_income = {
				years = 4
				trigger = {
					trade_goods = ivory
				}
				custom_tooltip = MONOPOLY_INCOME_IVORY_DESC
			}
		}
	}

	#Dev Capital
	zan_expand_the_capital = {
		icon = mission_central_asian_city
		required_missions = { zan_build_workshops }
		position = 3
		provinces_to_highlight = {
			province_id = 1196
			OR = {
				NOT = { owned_by = ROOT }
				NOT = { is_core = ROOT }
				NOT = { development = 20 }
			}
		}
		trigger = {
			owns_core_province = 1196
			1196 = {
				development = 20
				if = {
					limit = {
						has_dlc = "Leviathan"
					}
					has_great_project = {
						type = kilwa_city
						tier = 2
					}
				}
				else = {
					has_tax_building_trigger = yes
					has_trade_building_trigger = yes
				}
			}
		}
		effect = {
			1196 = {
				add_province_modifier = {
					name = zan_great_kilwa
					duration = -1
				}
			}
		}
	}

	#Build manufactories
	zan_build_manufactories = {
		icon = mission_have_manufactories
		required_missions = { zan_expand_the_capital }
		position = 4
		provinces_to_highlight = {
			owned_by = ROOT
			NOT = { trade_goods = gold }
			has_manufactory_trigger = no
		}
		trigger = {
			num_of_owned_provinces_with = {
				has_manufactory_trigger = yes
				value = 6
			}
		}
		effect = {
			custom_tooltip = zan_build_manufactories_ct
			hidden_effect = {
				while = {
					limit = {
						NOT = {
							num_of_owned_provinces_with = {
								has_province_flag = zan_manufactory_flag
								value = 6
							}
						}
					}
					random_owned_province = {
						limit = {
							has_manufactory_trigger = yes
							NOT = { has_province_flag = zan_manufactory_flag }
						}
						set_province_flag = zan_manufactory_flag
					}
				}
				every_owned_province = {
					limit = {
						has_province_flag = zan_manufactory_flag
					}
					add_base_production = 2
				}
			}
		}
	}
}

#Third slot
kilwa_trade_conquest_missions_slot = {
	slot = 3
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Origins"
	}
	potential = {
		has_dlc = "Origins"
		NOT = { map_setup = map_setup_random }
		tag = ZAN
	}
	has_country_shield = yes

	#Build up trade fleet
	zan_trade_fleet = {
		icon = mission_naval_dominance
		required_missions = {  }
		position = 1
		trigger = {
			num_of_light_ship = 25
		}
		effect = {
			add_navy_tradition = 20
			mombasa_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			northern_swahili_coast_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}

	#Conquer the coast
	zan_conquer_the_coast = {
		icon = mission_secure_the_malabar_coast
		required_missions = { zan_trade_fleet }
		position = 2
		provinces_to_highlight = {
			OR = {
				area = northern_swahili_coast_area
				area = mombasa_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			mombasa_area = {
				country_or_non_sovereign_subject_holds = ROOT
				type = all
			}
			northern_swahili_coast_area = {
				country_or_non_sovereign_subject_holds = ROOT
				type = all
			}
		}
		effect = {
			add_army_tradition = 15
			ajuuran_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			mogadishu_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}

	#Annex Mogadishu
	zan_conquer_mogadishu = {
		icon = mission_shipyards_of_gujarat
		required_missions = { zan_conquer_the_coast }
		position = 3
		provinces_to_highlight = {
			OR = {
				owned_by = MDI
				province_id = 2782
				province_id = 1205
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			owns_core_province = 1196
			MDI = {
				OR = {
					exists = no
					is_subject_of = ROOT
				}
			}
			owns_or_non_sovereign_subject_of = 1205
			owns_or_non_sovereign_subject_of = 2782
		}
		effect = {
			country_event = {
				id = flavor_zan.20
			}
		}
	}

	#Establish Dominance in Aden
	zan_dominate_gulf_of_aden = {
		icon = mission_dominate_trade_in_aden
		required_missions = { zan_conquer_mogadishu }
		position = 4
		provinces_to_highlight = {
			province_id = 4346
		}
		trigger = {
			4346 = {
				OR = {
					is_strongest_trade_power = ROOT
					trade_share = {
						country = ROOT
						share = 15
					}
				}
			}
		}
		effect = {
			4346 = {
				add_trade_modifier = {
					who = ROOT
					duration = 9125
					power = 10
					key = ZAN_DOMINATION
				}
			}
			add_country_modifier = {
				name = zan_kilwan_trade_dominance
				duration = 9125
			}
			custom_tooltip = zan_dominate_gulf_of_aden_ct
			hidden_effect = {
				add_claim = 504
				add_claim = 4457
				add_claim = 517
				add_claim = 529
				add_claim = 2089
				add_claim = 2030
				add_claim = 531
				add_claim = 4413
				add_claim = 534
				add_claim = 536
				add_claim = 2026
				add_claim = 4409
				add_claim = 572
			}
		}
	}

	#Make Zanzibar to the best trade node
	zan_centralize_trade = {
		icon = mission_south_indian_trade
		required_missions = { zan_dominate_gulf_of_aden }
		position = 5
		provinces_to_highlight = {
			OR = {
				AND = {
					OR = {
						province_id = 1448
						province_id = 1460
						province_id = 1466
					}
					NOT = {
						trade_share = {
							country = ROOT
							share = 75
						}
					}
				}
				AND = {
					OR = {
						province_id = 1191
						province_id = 4346
					}
					NOT = {
						trade_share = {
							country = ROOT
							share = 30
						}
					}
				}
				AND = {
					OR = {
						province_id = 4064
						province_id = 4097
						province_id = 504
						province_id = 1340
						province_id = 1361
						province_id = 1357
					}
					NOT = {
						trade_share = {
							country = ROOT
							share = 10
						}
					}
				}			
			}
		}
		trigger = {
			custom_trigger_tooltip = {
				tooltip = zan_centralize_trade_at
				OR = {
					1448 = { trade_share = { country = ROOT share = 85 } }
					1460 = { trade_share = { country = ROOT share = 85 } }
					1466 = { trade_share = { country = ROOT share = 85 } }
				}
			}
			custom_trigger_tooltip = {
				tooltip = zan_centralize_trade_bt
				OR = {
					1191 = { OR = { is_strongest_trade_power = ROOT trade_share = { country = ROOT share = 30 } } }
					4346 = { OR = { is_strongest_trade_power = ROOT trade_share = { country = ROOT share = 30 } } }
				}
			}
			custom_trigger_tooltip = {
				tooltip = zan_centralize_trade_ct
				OR = {
					504 = { OR = { is_strongest_trade_power = ROOT trade_share = { country = ROOT share = 10 } } }
					1340 = { OR = { is_strongest_trade_power = ROOT trade_share = { country = ROOT share = 10 } } }
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = zan_master_of_the_trade
				duration = -1
			}
		}
	}
}

#Fourth slot
kilwa_asia_trade_missions_slot = {
	slot = 4
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Origins"
	}
	potential = {
		has_dlc = "Origins"
		NOT = { map_setup = map_setup_random }
		tag = ZAN
	}
	has_country_shield = yes

	#Have a ton of transport + army
	zan_transport_fleet = {
		icon = mission_establish_high_seas_navy
		required_missions = {  }
		position = 1
		provinces_to_highlight = {
		}
		trigger = {
			army_size_percentage = 1
			num_of_transport = 10
		}
		effect = {
			madagascar_highlands_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			southern_madagascar = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			sakalava_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
			betsimasaraka_area = {
				limit = {
					NOT = { is_core = ROOT }
					NOT = { is_permanent_claim = ROOT }
				}
				add_permanent_claim = ROOT
			}
		}
	}

	#Conquer the whole island
	zan_conquer_madagascar = {
		icon = mission_kon_conquer_ksj
		required_missions = { zan_transport_fleet }
		position = 2
		provinces_to_highlight = {
			OR = {
				area = madagascar_highlands_area
				area = southern_madagascar
				area = sakalava_area
				area = betsimasaraka_area
			}
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				OR = {
					area = madagascar_highlands_area
					area = southern_madagascar
					area = sakalava_area
					area = betsimasaraka_area
				}
				value = 10
			}
		}
		effect = {
			custom_tooltip = zan_conquer_madagascar_tt
			hidden_effect = {
				madagascar_highlands_area = {
					limit = {
						country_or_non_sovereign_subject_holds = ROOT
					}
					add_province_modifier = {
						name = zan_conversion_of_fetishist
						duration = 9125
					}
				}
				southern_madagascar = {
					limit = {
						country_or_non_sovereign_subject_holds = ROOT
					}
					add_province_modifier = {
						name = zan_conversion_of_fetishist
						duration = 9125
					}
				}
				sakalava_area = {
					limit = {
						country_or_non_sovereign_subject_holds = ROOT
					}
					add_province_modifier = {
						name = zan_conversion_of_fetishist
						duration = 9125
					}
				}
				betsimasaraka_area = {
					limit = {
						country_or_non_sovereign_subject_holds = ROOT
					}
					add_province_modifier = {
						name = zan_conversion_of_fetishist
						duration = 9125
					}
				}
			}
		}
	}

	#Estrablish Trade Post in Malacca
	zan_dominate_the_malacca_trade = {
		icon = mission_market_place_with_asian_traders
		required_missions = { zan_explore_the_malacca_trade }
		position = 3
		provinces_to_highlight = {
			province_id = 1361
		}
		trigger = {
			1361 = {
				has_trader = ROOT
				OR = {
					trade_share = {
						country = ROOT
						share = 5
					}
					is_strongest_trade_power = ROOT
				}
			}
		}
		effect = {
			define_advisor = {
				type = trader
				discount = yes
				skill = 2
			}
			country_event = {
				id = flavor_zan.21
			}
		}
	}

	#Have trade power in China
	zan_trade_with_china = {
		icon = mission_asian_city
		required_missions = { zan_dominate_the_malacca_trade }
		position = 5
		provinces_to_highlight = {
			OR = {
				province_id = 1371
				province_id = 684
			}
		}
		trigger = {
			OR = {
				1371 = {
					OR = {
						is_strongest_trade_power = ROOT
						trade_share = {
							country = ROOT
							share = 25
						}
					}
				}
				684 = {
					OR = {
						is_strongest_trade_power = ROOT
						trade_share = {
							country = ROOT
							share = 25
						}
					}
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = zan_riches_of_china
				duration = -1
			}
		}
	}
}

#Fith slot
kilwa_colonization_missions_slot = {
	slot = 5
	generic = no
	ai = yes
	potential_on_load = {
		has_dlc = "Origins"
	}
	potential = {
		has_dlc = "Origins"
		NOT = { map_setup = map_setup_random }
		tag = ZAN
	}
	has_country_shield = yes

	#Have a merchant in any indian trade node
	zan_trade_of_the_east = {
		icon = mission_indian_empire
		required_missions = {  }
		position = 1
		provinces_to_highlight = {
			is_indian_trade_node_province = yes
		}
		trigger = {
			OR = {
				504 = { has_trader = ROOT }
				507 = { has_trader = ROOT }
				524 = { has_trader = ROOT }
				1343 = { has_trader = ROOT }
				1948 = { has_trader = ROOT }
				1340 = { has_trader = ROOT }
			}
		}
		effect = {
			add_country_modifier = {
				name = zan_trade_with_india
				duration = 9125
			}
			create_explorer = {
				tradition = 40
			}
		}
	}

	#Explore Malacca
	zan_explore_the_malacca_trade = {
		icon = mission_malayan_viceroyalty
		required_missions = { zan_trade_of_the_east }
		position = 2
		provinces_to_highlight = {
			OR = {
				region = indonesia_region
				region = malaya_region
			}
			NOT = { has_discovered = ROOT }
		}
		trigger = {
			indonesia_region = {
				has_discovered = ROOT
			}
			malaya_region = {
				NOT = { province_id = 1248 }
				has_discovered = ROOT
			}
		}
		effect = {
			custom_tooltip = zan_explore_the_malacca_trade_tt
			hidden_effect = {
				minangkabau_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				south_sumatra_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				north_sumatra_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				central_sumatra_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				batak_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				jambi_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				west_java_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				central_java_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				east_java_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				banten_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
				surabaya_area = {
					limit = {
						NOT = { is_core = ROOT }
						NOT = { is_permanent_claim = ROOT }
					}
					add_permanent_claim = ROOT
				}
			}
		}
	}

	#Have trade power in Moluccas
	zan_dominate_moluccas = {
		icon = mission_rb_colonise_spice_islands
		required_missions = { zan_explore_the_malacca_trade }
		position = 4
		provinces_to_highlight = {
			province_id = 1357
		}
		trigger = {
			1357 = {
				has_trader = ROOT
				OR = {
					trade_share = {
						country = ROOT
						share = 25
					}
					is_strongest_trade_power = ROOT
				}
			}
		}
		effect = {
			add_country_modifier = {
				name = zan_colonial_ambition
				duration = 9125
			}
		}
	}

	#Colonize Australia
	zan_colonize_australia = {
		icon = colonize_australia
		required_missions = { zan_dominate_moluccas }
		position = 5
		provinces_to_highlight = {
			colonial_region = colonial_australia
			NOT = { country_or_non_sovereign_subject_holds = ROOT }
		}
		trigger = {
			num_of_provinces_owned_or_owned_by_non_sovereign_subjects_with = {
				colonial_region = colonial_australia
				value = 10
			}
		}
		effect = {
			if = {
				limit = {
					num_of_subjects = 1
					any_subject_country = {
						capital_scope = {
							colonial_region = colonial_australia
						}
					}
				}
				random_subject_country = {
					limit = {
						num_of_subjects = 1
						any_subject_country = {
							capital_scope = {
								colonial_region = colonial_australia
							}
						}
					}
					colonial_australia = {
						add_permanent_claim = PREV
					}
				}
			}
			else = {
				colonial_australia = {
					add_permanent_claim = ROOT
				}
			}
			add_country_modifier = {
				name = zan_australian_colony
				duration = -1
			}
		}
	}
}